package com.gs.common.tool.utils;

import com.google.common.collect.Lists;
import com.gs.common.tool.pojo.AnnotationInfo;

import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

/**
 * lombok 工具类
 * @author: guos
 * @date: 2025/09/10 17:49
 **/
public class LombokUtil {


    public static void main(String[] args) {
        List<AnnotationInfo> annotationInfos = LombokUtil.addAnnotationShortName(false);
        String lombokShortName = getAnnotationShortName(annotationInfos);
        System.out.println(lombokShortName);
    }


    /**
     * 添加lombok通用注解简称
     * @param haveSuperClz    是否有父类
     * @date 2025/09/10 17:51
     **/
    public static List<AnnotationInfo> addAnnotationShortName(boolean haveSuperClz) {
        List<AnnotationInfo> annotationList = Lists.newArrayList();
        if (haveSuperClz) {
            annotationList.add(new AnnotationInfo("EqualsAndHashCode", Lists.newArrayList(new AnnotationInfo.Field("callSuper", "true"))));
        }
        annotationList.add(new AnnotationInfo("Data", null));
        annotationList.add(new AnnotationInfo("Builder", null));
        annotationList.add(new AnnotationInfo("NoArgsConstructor", null));
        annotationList.add(new AnnotationInfo("AllArgsConstructor", null));
        annotationList.add(new AnnotationInfo("FieldNameConstants", null));
        annotationList.add(new AnnotationInfo("Accessors", Lists.newArrayList(new AnnotationInfo.Field("chain", "true"))));
        return annotationList;
    }


    /**
     * 添加lombok通用注解全称
     * @param haveSuperClz    是否有父类
     * @date 2025/09/10 18:09
     **/
    public static List<String> addAnnotationFullName(boolean haveSuperClz) {
        List<String> thirdClzNameList = Lists.newArrayList("lombok.Data", "lombok.NoArgsConstructor", "lombok.AllArgsConstructor",
                "lombok.experimental.FieldNameConstants", "lombok.Builder", "lombok.experimental.Accessors");
        if (haveSuperClz) {
            thirdClzNameList.add("lombok.EqualsAndHashCode");
        }
        return thirdClzNameList;
    }


    /**
     * 获取注解简称名称
     * @param annotationInfos    注解集合
     * @date 2025/09/10 20:01
     **/
    public static String getAnnotationShortName(List<AnnotationInfo> annotationInfos) {
        if (CollectionUtil.isEmpty(annotationInfos)) {
            return null;
        }
        return annotationInfos.stream().map(d -> {
            if (CollectionUtil.isEmpty(d.getFieldList())) {
                return String.format("@%s", d.getName());
            } else {
                return String.format("@%s(%s)", d.getName(), d.getFieldList().stream().map(v -> StringUtil.isEmpty(v.getValue()) ? String.format("\"%s\"", v.getName()) : String.format("%s = %s", v.getName(), Objects.equals(v.getHaveQuot(), true) ? String.format("\"%s\"", v.getValue()) : v.getValue())).collect(Collectors.joining(",")));
            }
        }).collect(Collectors.joining("\n"));
    }
}
